feat(opencode): add killswitch indicators to TUI sidebar#39
Conversation
There was a problem hiding this comment.
2 issues found across 16 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Fix all with cubic | Re-trigger cubic
84f44e5 to
583586a
Compare
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
09b34c3 to
8339edc
Compare
e86d9d3 to
a8d6404
Compare
a8d6404 to
ecffae9
Compare
4988ae1 to
78b02b4
Compare
eaf91c9 to
3147ad3
Compare
|
Updated: this branch now carries the sidebar quota fix (#57) and the collapsible sidebar (#58), and integrates the collapsed view with the killswitch indicators — the collapsed active-account row shows a red ⊘ (instead of the usage dot) when that account is killswitch-blocked; |
…reshold Self-review fixes folded in: - Token-aware fail-closed read: const mainQuota = quotaManager.getMain(auth.access) so a previous main account's cached quota can't satisfy the fail-closed check or feed the killswitch eval after a main-account switch. - Removed a stray inner 'let sessionRequestCount = 0' + unconditional increment that shadowed the process-scoped counter, which had left the active-route fallback every-N refresh reading a never-incremented counter.
Layer killswitch awareness onto the restyled sidebar (killed state in SidebarState + writeSidebarState via killswitchPassesPolicy, blocked status word, Killswitch health row, degraded/LIMITED inclusion). Also restores the process-scoped 'let sessionRequestCount' (a prior cascade had flipped it to const, which left the active-route fallback every-N refresh reading a never-incremented counter).
c73b37e to
5eb08e5
Compare
There was a problem hiding this comment.
iceteaSA has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Adds killswitch awareness to the TUI sidebar widget (the integration of #35 + the merged sidebar):
blocked(red) state for killswitch-killed main and fallback accounts.Killswitchrow in the Health section and inclusion in theLIMITEDbadge.writeSidebarState()computes killswitch policy for every account using fresh, token-aware QuotaManager reads (never the stale request-start snapshot).Files:
packages/opencode/src/sidebar-state.ts— addskilled+ backoff fieldspackages/opencode/src/tui.tsx— blocked indicator + kill status sectionpackages/opencode/src/index.ts— killswitch-aware sidebar stateSummary by cubic
Adds a killswitch that hard-blocks accounts when quota drops below configured thresholds and integrates it into routing and the TUI;
/claude-killswitchmanages thresholds. Killed accounts never route, and when none are routable we return a synthetic 429 withretry-afterfrom the earliest reset.New Features
getRoutableFallbackAccountsfilter across all routes, non‑replayable bodies never fall through, and a hard 429 withretry-afterfrom the earliest reset (+60s buffer).killedflags for main/fallbacks,resolveActiveAccount()correction, and background fallback storage changes re‑render viaonFallbackStorageChanged./claude-killswitch(status,on,off,set main|all|<id>:<5h>,<1w>); changes persist via@cortexkit/anthropic-auth-core.Bug Fixes
Written for commit 5eb08e5. Summary will update on new commits.
Greptile Summary
This PR wires killswitch awareness into the OpenCode TUI sidebar:
killedflags on main and fallback accounts, a collapsed header with active-account quota and a red ⊘ blocked indicator, a Killswitch row in the Health section, and a/claude-killswitchcommand for managing per-account hard-block thresholds. The core routing gate inindex.tsaddresses the previously flagged issues around stale quota on first request, non-replayable body handling, and the disagreement betweenallFallbacksKilledandsurvivingFallbacks.packages/core/src/accounts.ts+killswitch.ts:killswitchPassesPolicycorrectly defers the unknown-window decision so a present below-threshold window always blocks even when the other window is missing;killswitchRetryAfterSecondspicks the earliest reset across all accounts and adds a 60-second buffer.packages/opencode/src/index.ts: Eager quota refresh before killswitch evaluation, token-awaremainQuotare-read after refresh,getRoutableFallbackAccountsas the single source of truth for all fallback-selection paths, and non-replayable bodies treated as having zero survivors.packages/opencode/src/tui.tsx: Collapsible header (click to toggle), collapsed view showing active-account 5h usage, and the Killswitch StatRow — though this row is currently placed outside the<Show when={degraded()}>Health block rather than inside it.Confidence Score: 4/5
The killswitch gate is safe to merge — the three routing bugs identified in earlier review threads are addressed and backed by targeted integration tests.
The routing logic in index.ts is complex and the fixes look correct. The one remaining finding — the Killswitch StatRow placed outside the Health Show block — is purely structural and does not change the visual output today, but is a latent maintainability concern.
packages/opencode/src/tui.tsx — Killswitch StatRow placement outside the degraded Show block.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Fetch request arrives] --> B{failClosedOnUnknownQuota\n+ no quota + backed off?} B -- Yes --> C[Return synthetic 429\nwith quota backoff retry-after] B -- No --> D{killswitch enabled?} D -- No --> K[Normal routing] D -- Yes --> E{needsRefresh?} E -- Yes --> F[Eager refresh:\nrefreshMain + refreshAllFallbacks] F --> G[Re-read mainQuota\ntoken-aware] E -- No --> G G --> H{killswitchPassesPolicy\nmainQuota?} H -- Pass --> K H -- Fail: main killed --> I{isReplayableRequest?} I -- Yes --> J[getRoutableFallbackAccounts\nusable ∩ killswitch-pass] I -- No --> N[survivingFallbacks = empty] J --> L{surviving\nfallbacks > 0?} N --> M L -- Yes --> M2[tryUsableFallbackAccounts\nhard block: never fall through to main] M2 --> M2r{fallbackResponse?} M2r -- Yes --> M2s[Return fallback response] M2r -- No --> M[Return synthetic 429\nkillswitchRetryAfterSeconds] L -- No --> MReviews (11): Last reviewed commit: "docs(opencode): clarify version path lay..." | Re-trigger Greptile